package com.monkey.luffer.design.pattern;

import lombok.Data;

import java.nio.Buffer;

/**
 * @author dkb
 * @date 2020/11/14
 */
@Data
public class NutritionFacts {
    private int servingSize;

    private int servings;

    private int calories;

    private int fat;

    private int sodium;

    private int carbohydrate;

    /**
     * Builder build模式 建立static内部类
     *
     * @author dkb
     * @date 2020/11/14
     */
    public static class Builder {
        private final int servingSize;

        private final int servings;

        private int calories;

        private int fat;

        private int sodium;

        private int carbohydrate;

        public Builder(int servingSize, int servings) {
            this.servings = servings;
            this.servingSize = servingSize;
        }

        public Builder calories(int var) {
            calories = var;
            return this;
        }

        public Builder fat(int var) {
            fat = var;
            return this;
        }

        public Builder sodium(int var) {
            sodium = var;
            return this;
        }

        public Builder carbohydrate(int var) {
            carbohydrate = var;
            return this;
        }

        public NutritionFacts build() {
            return new NutritionFacts(this);
        }


    }

    public NutritionFacts(Builder builder) {
        servingSize = builder.servingSize;
        servings = builder.servings;
        calories = builder.calories;
        fat = builder.fat;
        sodium = builder.sodium;
        carbohydrate = builder.carbohydrate;
    }

    public static void main(String[] args) {
        //建造者模式构建对象
        NutritionFacts nutritionFacts = new Builder(240, 8).sodium(10).calories(20).build();
        System.out.println(nutritionFacts.getSodium());

    }


}
